home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / libs / rawkey-0.2 / rawkey-0 / rawkey / testprog.c < prev   
Encoding:
C/C++ Source or Header  |  1994-10-23  |  1.3 KB  |  56 lines

  1. /* testprog - simple example of how to use the rawkey library (using svgalib).
  2.  *
  3.  * The cursor keys move a dot around the screen - esc or x ends.
  4.  * Using scan_keyboard() and is_key_pressed() obviously allows you to have
  5.  * more than one key pressed at once, and avoids the key repeat problem.
  6.  *
  7.  * Feel free to pinch bits out of this, or whatever.
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <unistd.h>
  12. #include <vga.h>
  13. #include <rawkey.h>
  14.  
  15.  
  16. main()
  17. {
  18. int c,x,y,f;
  19.  
  20. vga_init();
  21.  
  22. vga_setmode(G320x200x256);
  23.  
  24. if(!rawmode_init())
  25.   {
  26.   printf("Couldn't startup RAW mode - /dev/tty0 unreadable?\n");
  27.   exit(1);
  28.   }
  29.  
  30. x=160; y=100;
  31.  
  32. do
  33.   {
  34.   vga_drawpixel(x,y);
  35.   usleep(10000);    /* sleep for a bit to avoid burning CPU */
  36.  
  37.   scan_keyboard();
  38.  
  39.   /* the CURSOR_LEFT etc. are defined in rawkey.h, and are scancodes -
  40.    * for, say, the Q key, you'd say "scancode_trans('q')".
  41.    * note that symbols only obtained by shifting won't be recognised by
  42.    * scancode_trans(), so you should only really use it for alphanumerics.
  43.    */
  44.   if(is_key_pressed(CURSOR_LEFT)  && x>0)    x--;
  45.   if(is_key_pressed(CURSOR_RIGHT) && x<319)    x++;
  46.   if(is_key_pressed(CURSOR_UP)    && y>0)    y--;
  47.   if(is_key_pressed(CURSOR_DOWN)  && y<199)    y++;
  48.   }
  49. while(!is_key_pressed(scancode_trans('x')) && !is_key_pressed(ESCAPE_KEY));
  50.  
  51. vga_setmode(TEXT);
  52.  
  53. rawmode_exit();
  54. exit(0);
  55. }
  56.